Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / common / src / commonMain / kotlin / org / meshtastic / core / common / state / FirmwareMaintenanceLock.kt

Displaying Raw • Download

core/common/src/commonMain/kotlin/org/meshtastic/core/common/state/FirmwareMaintenanceLock.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 2.36 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.common.state

Tff7b72import T7ee787kotlinx.atomicfu.atomic
Tff7b72import T7ee787org.koin.core.annotation.Single

T8b949e/**
* Marks a USB firmware-maintenance sequence as in flight, so the radio transport does not fight it for the device.
*
* A factory erase leaves the device enumerating as a bare CDC port with no Meshtastic protocol on it. The serial
* transport will happily bind to that — its device lookup falls back to whatever probed device it can find, not just
* the saved address — and the environmental-recovery listeners re-enter transport startup whenever Bluetooth or the
* network flips. Both would claim the port the maintenance flow needs.
*
* Lives in `:core:common` because the two parties sit in modules that cannot see each other: the flow that takes the
* lock is in `:feature:firmware`, and the code that must respect it is in `:core:service`.
*
* The consequence of ignoring the lock is bounded rather than destructive — a transport that claims the port asserts
* DTR itself, which happens to unblock the erase — but it makes the flow's own signal unreliable, and a mesh handshake
* against erase firmware is noise nobody needs to debug.
*/
Tf0883e@Single
Tff7b72class T56d364FirmwareMaintenanceLock Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3active Tff7b72= Te6edf3atomicTb4b4b4(Tff7b72falseTb4b4b4)

T8b949e/** True while a maintenance sequence holds the lock. */
Tff7b72val Te6edf3isActiveTb4b4b4: Tffa657Boolean
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3activeTb4b4b4.Te6edf3value

T8b949e/** Takes the lock. Idempotent — re-taking an already-held lock is a no-op. */
Tff7b72fun Td2a8ffacquireTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3activeTb4b4b4.Te6edf3value Tff7b72= Tff7b72true
Tb4b4b4}

T8b949e/** Releases the lock. Must run even on failure, so callers use `try`/`finally`. */
Tff7b72fun Td2a8ffreleaseTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3activeTb4b4b4.Te6edf3value Tff7b72= Tff7b72false
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s